<?php
	include "../../public/commom/config.php";
	include "../lock2.php";
	include "../../public/commom/thumb.php";
	include "../../public/commom/commom.php";
	
	if($_POST){
		$name = $_POST["name"];
		$cid = $_POST["class_id"];
		
		/*图片*/
		$imgsrc = $_FILES["img"]["tmp_name"];//获取图片临时路径
		$fname = $_FILES["img"]["name"];//获取图片名称
		$a = explode(".", $fname);//获取图片后缀名
		$ext = array_pop($a);//
		$dst = $uploadPath . time().mt_rand(). "." . $ext;//随机生成图片名称

		//图片上传成功
		if(move_uploaded_file($imgsrc, $dst)) {
			thumb($dst, 200, 200);//生成缩略图
			$img = basename($dst);//获取带后缀名的图片名称
		}
		
		$sql = "INSERT INTO brand (name, img, class_id) VALUES ('$name', '$img', '$cid')";
			
		$result = mysqli_query($conn, $sql);
			
		mysqli_close($conn);
				
		header("Location: ./index.php");
	}
?>